package cn.lysj.framework.customer.service;

import cn.lysj.framework.base.BaseService;
import cn.lysj.framework.common.utils.web.Resp;
import cn.lysj.framework.coupon.service.CouponService;
import cn.lysj.framework.customer.domain.CustomerVipCoupon;
import cn.lysj.framework.customer.repository.CustomerVipCouponRepository;
import cn.lysj.framework.customer.vo.CustomerVipCouponVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author zwj
 * @description 用户优惠券服务层
 * @create 2019-01-15 15:44:14
 **/
@Slf4j
@Service
@Transactional
public class CustomerVipCouponService implements BaseService<CustomerVipCoupon> {
    @Resource
    private CouponService couponService;

    @Resource
    private CustomerVipCouponRepository customerVipCouponRepository;

    @Override
    public CustomerVipCouponRepository getRepository() {
        return customerVipCouponRepository;
    }



    /**
     * @author ZhangWenJian
     * @date 2019/1/16 13:32
     * @title getCustomerVipCoupon
     * @param customerVipId
     * @return cn.lysj.framework.common.utils.web.Resp
     * @description 获取Vip用户的优惠券信息
     */
    public Resp getCustomerVipCoupon(String customerVipId){
        List<CustomerVipCouponVo> customerVipCoupons = customerVipCouponRepository.findCustomerVipAllCoupon(customerVipId);
        return new Resp(customerVipCoupons,"获取用户优惠券信息成功!");
    }

    public Resp getCustomerVipCouponForUse(String customerVipId, BigDecimal useMoney){
        List<CustomerVipCouponVo> customerVipCoupons = customerVipCouponRepository.getCustomerVipCouponForUse(customerVipId,useMoney,new Date());
        return new Resp(customerVipCoupons,"获取可使用的优惠券信息成功!");
    }
    /**
     * @author ZhangWenJian
     * @date 2019/1/17 18:06
     * @title findCustomerVipCouponInValid
     * @param customerVipId
     * @return cn.lysj.framework.common.utils.web.Resp
     * @description 查询用户可以使用的优惠券
     */
    public Resp findCustomerVipCouponInValid(String customerVipId){
        List<CustomerVipCouponVo> customerVipCoupons = customerVipCouponRepository.findCustomerVipCouponInValid(customerVipId,1,new Date());
        return new Resp(customerVipCoupons,"获取用户可以使用优惠券信息成功!");
    }
    /**
     * @author ZhangWenJian
     * @date 2019/1/17 18:06
     * @title findCustomerVipAllCouponInUsed
     * @param customerVipId
     * @return cn.lysj.framework.common.utils.web.Resp
     * @description 查询用户已经使用过的优惠券
     */
    public Resp findCustomerVipAllCouponInUsed(String customerVipId){
        List<CustomerVipCouponVo> customerVipCoupons = customerVipCouponRepository.findCustomerVipAllCouponInUsed(customerVipId,2);
        return new Resp(customerVipCoupons,"获取用户已经使用过的优惠券信息成功!");
    }
    /**
     * @author ZhangWenJian
     * @date 2019/1/17 18:06
     * @title findCustomerVipAllCouponInPastDue
     * @param customerVipId
     * @return cn.lysj.framework.common.utils.web.Resp
     * @description 查询用户过期的优惠券
     */
    public Resp findCustomerVipAllCouponInPastDue(String customerVipId){
        List<CustomerVipCouponVo> customerVipCoupons = customerVipCouponRepository.findCustomerVipAllCouponInPastDue(customerVipId,1,new Date());
        return new Resp(customerVipCoupons,"获取用户过期优惠券信息成功!");
    }
}
